package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class ReflectDemo6 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Method method = cls.getMethod("say", String.class, int.class);
        String name = method.getName();
        System.out.println("方法名："+ name);
        //返回值类型
        Class returnType = method.getReturnType();
        System.out.println("返回值类型："+ returnType);
        //获取方法参数类型
        Class[] paramTypes = method.getParameterTypes();
        for(Class paramType:paramTypes){
            System.out.println("参数类型："+ paramType);
        }
        //获取方法参数个数
        int count = method.getParameterCount();
        System.out.println("参数个数："+ count);
        //获取方法修饰符
        int modifiers = method.getModifiers();
        switch (modifiers){
            case Modifier.PUBLIC:
                System.out.println("public");
                break;
            case Modifier.PRIVATE:
                System.out.println("private");
                break;
            case Modifier.PROTECTED:
                System.out.println("protected");
                break;
            case Modifier.STATIC:
                System.out.println("static");
                break;
            case Modifier.FINAL:
                System.out.println("final");
                break;
        }
    }
}
